#!/usr/bin/env python
import logging
from binance.um_futures import UMFutures
from binance.lib.utils import config_logging
import logging
from binance.um_futures import UMFutures
from binance.lib.utils import config_logging
from binance.error import ClientError

config_logging(logging, logging.INFO)

key = "z4U7noE4iEkLPVi3z02yq4iKvnUkeOslYXRzNKQhFFMni3dzsjmdjfQXZWvuS9Am"
secret = "mEEpNcWyeSEcHbvkpPTPGJRWgTX0iS7QjCA2aaMHUTgyOuCRPTm8Y7HByPnPaWQ5"

um_futures_client = UMFutures(key=key, secret=secret,proxies={'https':'http://127.0.0.1:7890'})

klines = um_futures_client.klines(limit=5,symbol="BTCUSDT", interval="1m")
kline = klines[-1]
price = kline[4]
logging.info(kline)

try:
    # response = um_futures_client.change_leverage(
    #     symbol="LTCUSDT", leverage=75, recvWindow=6000
    # )
    # logging.info(response)
    response = um_futures_client.new_order(
        symbol="BTCUSDT",
        side="BUY",
        type="MARKET",
        quantity=0.05,
        positionSide="LONG",
    )

    logging.info(response)
    orderId = response['orderId']


except ClientError as error:
    logging.error(
        "Found error. status: {}, error code: {}, error message: {}".format(
            error.status_code, error.error_code, error.error_message
        )
    )

